package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.FlowConfig;
import com.xjgzinfo.usdp.domain.PageSchema;
import com.xjgzinfo.usdp.repository.FlowConfigRepository;
import com.xjgzinfo.usdp.service.FlowConfigService;
import com.xjgzinfo.usdp.service.dto.FlowConfigDTO;
import com.xjgzinfo.usdp.service.mapper.FlowConfigMapper;
import com.xjgzinfo.usdp.service.dto.FlowConfigCriteria;
import com.xjgzinfo.usdp.service.FlowConfigQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link FlowConfigResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class FlowConfigResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_DATA = "AAAAAAAAAA";
    private static final String UPDATED_DATA = "BBBBBBBBBB";

    private static final String DEFAULT_INSTANCE_ID = "AAAAAAAAAA";
    private static final String UPDATED_INSTANCE_ID = "BBBBBBBBBB";

    private static final String DEFAULT_CREATE_USER = "AAAAAAAAAA";
    private static final String UPDATED_CREATE_USER = "BBBBBBBBBB";

    private static final String DEFAULT_UPDATE_USER = "AAAAAAAAAA";
    private static final String UPDATED_UPDATE_USER = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final Instant DEFAULT_UPDATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_UPDATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    @Autowired
    private FlowConfigRepository flowConfigRepository;

    @Autowired
    private FlowConfigMapper flowConfigMapper;

    @Autowired
    private FlowConfigService flowConfigService;

    @Autowired
    private FlowConfigQueryService flowConfigQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restFlowConfigMockMvc;

    private FlowConfig flowConfig;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static FlowConfig createEntity(EntityManager em) {
        FlowConfig flowConfig = new FlowConfig()
            .name(DEFAULT_NAME)
            .data(DEFAULT_DATA)
            .instanceId(DEFAULT_INSTANCE_ID)
            .createUser(DEFAULT_CREATE_USER)
            .updateUser(DEFAULT_UPDATE_USER)
            .createTime(DEFAULT_CREATE_TIME)
            .updateTime(DEFAULT_UPDATE_TIME);
        return flowConfig;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static FlowConfig createUpdatedEntity(EntityManager em) {
        FlowConfig flowConfig = new FlowConfig()
            .name(UPDATED_NAME)
            .data(UPDATED_DATA)
            .instanceId(UPDATED_INSTANCE_ID)
            .createUser(UPDATED_CREATE_USER)
            .updateUser(UPDATED_UPDATE_USER)
            .createTime(UPDATED_CREATE_TIME)
            .updateTime(UPDATED_UPDATE_TIME);
        return flowConfig;
    }

    @BeforeEach
    public void initTest() {
        flowConfig = createEntity(em);
    }

    @Test
    @Transactional
    public void createFlowConfig() throws Exception {
        int databaseSizeBeforeCreate = flowConfigRepository.findAll().size();
        // Create the FlowConfig
        FlowConfigDTO flowConfigDTO = flowConfigMapper.toDto(flowConfig);
        restFlowConfigMockMvc.perform(post("/api/flow-configs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(flowConfigDTO)))
            .andExpect(status().isCreated());

        // Validate the FlowConfig in the database
        List<FlowConfig> flowConfigList = flowConfigRepository.findAll();
        assertThat(flowConfigList).hasSize(databaseSizeBeforeCreate + 1);
        FlowConfig testFlowConfig = flowConfigList.get(flowConfigList.size() - 1);
        assertThat(testFlowConfig.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testFlowConfig.getData()).isEqualTo(DEFAULT_DATA);
        assertThat(testFlowConfig.getInstanceId()).isEqualTo(DEFAULT_INSTANCE_ID);
        assertThat(testFlowConfig.getCreateUser()).isEqualTo(DEFAULT_CREATE_USER);
        assertThat(testFlowConfig.getUpdateUser()).isEqualTo(DEFAULT_UPDATE_USER);
        assertThat(testFlowConfig.getCreateTime()).isEqualTo(DEFAULT_CREATE_TIME);
        assertThat(testFlowConfig.getUpdateTime()).isEqualTo(DEFAULT_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void createFlowConfigWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = flowConfigRepository.findAll().size();

        // Create the FlowConfig with an existing ID
        flowConfig.setId(1L);
        FlowConfigDTO flowConfigDTO = flowConfigMapper.toDto(flowConfig);

        // An entity with an existing ID cannot be created, so this API call must fail
        restFlowConfigMockMvc.perform(post("/api/flow-configs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(flowConfigDTO)))
            .andExpect(status().isBadRequest());

        // Validate the FlowConfig in the database
        List<FlowConfig> flowConfigList = flowConfigRepository.findAll();
        assertThat(flowConfigList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = flowConfigRepository.findAll().size();
        // set the field null
        flowConfig.setName(null);

        // Create the FlowConfig, which fails.
        FlowConfigDTO flowConfigDTO = flowConfigMapper.toDto(flowConfig);


        restFlowConfigMockMvc.perform(post("/api/flow-configs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(flowConfigDTO)))
            .andExpect(status().isBadRequest());

        List<FlowConfig> flowConfigList = flowConfigRepository.findAll();
        assertThat(flowConfigList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllFlowConfigs() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList
        restFlowConfigMockMvc.perform(get("/api/flow-configs?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(flowConfig.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].data").value(hasItem(DEFAULT_DATA.toString())))
            .andExpect(jsonPath("$.[*].instanceId").value(hasItem(DEFAULT_INSTANCE_ID)))
            .andExpect(jsonPath("$.[*].createUser").value(hasItem(DEFAULT_CREATE_USER)))
            .andExpect(jsonPath("$.[*].updateUser").value(hasItem(DEFAULT_UPDATE_USER)))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].updateTime").value(hasItem(DEFAULT_UPDATE_TIME.toString())));
    }
    
    @Test
    @Transactional
    public void getFlowConfig() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get the flowConfig
        restFlowConfigMockMvc.perform(get("/api/flow-configs/{id}", flowConfig.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(flowConfig.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.data").value(DEFAULT_DATA.toString()))
            .andExpect(jsonPath("$.instanceId").value(DEFAULT_INSTANCE_ID))
            .andExpect(jsonPath("$.createUser").value(DEFAULT_CREATE_USER))
            .andExpect(jsonPath("$.updateUser").value(DEFAULT_UPDATE_USER))
            .andExpect(jsonPath("$.createTime").value(DEFAULT_CREATE_TIME.toString()))
            .andExpect(jsonPath("$.updateTime").value(DEFAULT_UPDATE_TIME.toString()));
    }


    @Test
    @Transactional
    public void getFlowConfigsByIdFiltering() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        Long id = flowConfig.getId();

        defaultFlowConfigShouldBeFound("id.equals=" + id);
        defaultFlowConfigShouldNotBeFound("id.notEquals=" + id);

        defaultFlowConfigShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultFlowConfigShouldNotBeFound("id.greaterThan=" + id);

        defaultFlowConfigShouldBeFound("id.lessThanOrEqual=" + id);
        defaultFlowConfigShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllFlowConfigsByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where name equals to DEFAULT_NAME
        defaultFlowConfigShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the flowConfigList where name equals to UPDATED_NAME
        defaultFlowConfigShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where name not equals to DEFAULT_NAME
        defaultFlowConfigShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the flowConfigList where name not equals to UPDATED_NAME
        defaultFlowConfigShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByNameIsInShouldWork() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where name in DEFAULT_NAME or UPDATED_NAME
        defaultFlowConfigShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the flowConfigList where name equals to UPDATED_NAME
        defaultFlowConfigShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where name is not null
        defaultFlowConfigShouldBeFound("name.specified=true");

        // Get all the flowConfigList where name is null
        defaultFlowConfigShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllFlowConfigsByNameContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where name contains DEFAULT_NAME
        defaultFlowConfigShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the flowConfigList where name contains UPDATED_NAME
        defaultFlowConfigShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByNameNotContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where name does not contain DEFAULT_NAME
        defaultFlowConfigShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the flowConfigList where name does not contain UPDATED_NAME
        defaultFlowConfigShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllFlowConfigsByInstanceIdIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where instanceId equals to DEFAULT_INSTANCE_ID
        defaultFlowConfigShouldBeFound("instanceId.equals=" + DEFAULT_INSTANCE_ID);

        // Get all the flowConfigList where instanceId equals to UPDATED_INSTANCE_ID
        defaultFlowConfigShouldNotBeFound("instanceId.equals=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByInstanceIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where instanceId not equals to DEFAULT_INSTANCE_ID
        defaultFlowConfigShouldNotBeFound("instanceId.notEquals=" + DEFAULT_INSTANCE_ID);

        // Get all the flowConfigList where instanceId not equals to UPDATED_INSTANCE_ID
        defaultFlowConfigShouldBeFound("instanceId.notEquals=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByInstanceIdIsInShouldWork() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where instanceId in DEFAULT_INSTANCE_ID or UPDATED_INSTANCE_ID
        defaultFlowConfigShouldBeFound("instanceId.in=" + DEFAULT_INSTANCE_ID + "," + UPDATED_INSTANCE_ID);

        // Get all the flowConfigList where instanceId equals to UPDATED_INSTANCE_ID
        defaultFlowConfigShouldNotBeFound("instanceId.in=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByInstanceIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where instanceId is not null
        defaultFlowConfigShouldBeFound("instanceId.specified=true");

        // Get all the flowConfigList where instanceId is null
        defaultFlowConfigShouldNotBeFound("instanceId.specified=false");
    }
                @Test
    @Transactional
    public void getAllFlowConfigsByInstanceIdContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where instanceId contains DEFAULT_INSTANCE_ID
        defaultFlowConfigShouldBeFound("instanceId.contains=" + DEFAULT_INSTANCE_ID);

        // Get all the flowConfigList where instanceId contains UPDATED_INSTANCE_ID
        defaultFlowConfigShouldNotBeFound("instanceId.contains=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByInstanceIdNotContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where instanceId does not contain DEFAULT_INSTANCE_ID
        defaultFlowConfigShouldNotBeFound("instanceId.doesNotContain=" + DEFAULT_INSTANCE_ID);

        // Get all the flowConfigList where instanceId does not contain UPDATED_INSTANCE_ID
        defaultFlowConfigShouldBeFound("instanceId.doesNotContain=" + UPDATED_INSTANCE_ID);
    }


    @Test
    @Transactional
    public void getAllFlowConfigsByCreateUserIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createUser equals to DEFAULT_CREATE_USER
        defaultFlowConfigShouldBeFound("createUser.equals=" + DEFAULT_CREATE_USER);

        // Get all the flowConfigList where createUser equals to UPDATED_CREATE_USER
        defaultFlowConfigShouldNotBeFound("createUser.equals=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateUserIsNotEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createUser not equals to DEFAULT_CREATE_USER
        defaultFlowConfigShouldNotBeFound("createUser.notEquals=" + DEFAULT_CREATE_USER);

        // Get all the flowConfigList where createUser not equals to UPDATED_CREATE_USER
        defaultFlowConfigShouldBeFound("createUser.notEquals=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateUserIsInShouldWork() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createUser in DEFAULT_CREATE_USER or UPDATED_CREATE_USER
        defaultFlowConfigShouldBeFound("createUser.in=" + DEFAULT_CREATE_USER + "," + UPDATED_CREATE_USER);

        // Get all the flowConfigList where createUser equals to UPDATED_CREATE_USER
        defaultFlowConfigShouldNotBeFound("createUser.in=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateUserIsNullOrNotNull() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createUser is not null
        defaultFlowConfigShouldBeFound("createUser.specified=true");

        // Get all the flowConfigList where createUser is null
        defaultFlowConfigShouldNotBeFound("createUser.specified=false");
    }
                @Test
    @Transactional
    public void getAllFlowConfigsByCreateUserContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createUser contains DEFAULT_CREATE_USER
        defaultFlowConfigShouldBeFound("createUser.contains=" + DEFAULT_CREATE_USER);

        // Get all the flowConfigList where createUser contains UPDATED_CREATE_USER
        defaultFlowConfigShouldNotBeFound("createUser.contains=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateUserNotContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createUser does not contain DEFAULT_CREATE_USER
        defaultFlowConfigShouldNotBeFound("createUser.doesNotContain=" + DEFAULT_CREATE_USER);

        // Get all the flowConfigList where createUser does not contain UPDATED_CREATE_USER
        defaultFlowConfigShouldBeFound("createUser.doesNotContain=" + UPDATED_CREATE_USER);
    }


    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateUserIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateUser equals to DEFAULT_UPDATE_USER
        defaultFlowConfigShouldBeFound("updateUser.equals=" + DEFAULT_UPDATE_USER);

        // Get all the flowConfigList where updateUser equals to UPDATED_UPDATE_USER
        defaultFlowConfigShouldNotBeFound("updateUser.equals=" + UPDATED_UPDATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateUserIsNotEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateUser not equals to DEFAULT_UPDATE_USER
        defaultFlowConfigShouldNotBeFound("updateUser.notEquals=" + DEFAULT_UPDATE_USER);

        // Get all the flowConfigList where updateUser not equals to UPDATED_UPDATE_USER
        defaultFlowConfigShouldBeFound("updateUser.notEquals=" + UPDATED_UPDATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateUserIsInShouldWork() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateUser in DEFAULT_UPDATE_USER or UPDATED_UPDATE_USER
        defaultFlowConfigShouldBeFound("updateUser.in=" + DEFAULT_UPDATE_USER + "," + UPDATED_UPDATE_USER);

        // Get all the flowConfigList where updateUser equals to UPDATED_UPDATE_USER
        defaultFlowConfigShouldNotBeFound("updateUser.in=" + UPDATED_UPDATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateUserIsNullOrNotNull() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateUser is not null
        defaultFlowConfigShouldBeFound("updateUser.specified=true");

        // Get all the flowConfigList where updateUser is null
        defaultFlowConfigShouldNotBeFound("updateUser.specified=false");
    }
                @Test
    @Transactional
    public void getAllFlowConfigsByUpdateUserContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateUser contains DEFAULT_UPDATE_USER
        defaultFlowConfigShouldBeFound("updateUser.contains=" + DEFAULT_UPDATE_USER);

        // Get all the flowConfigList where updateUser contains UPDATED_UPDATE_USER
        defaultFlowConfigShouldNotBeFound("updateUser.contains=" + UPDATED_UPDATE_USER);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateUserNotContainsSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateUser does not contain DEFAULT_UPDATE_USER
        defaultFlowConfigShouldNotBeFound("updateUser.doesNotContain=" + DEFAULT_UPDATE_USER);

        // Get all the flowConfigList where updateUser does not contain UPDATED_UPDATE_USER
        defaultFlowConfigShouldBeFound("updateUser.doesNotContain=" + UPDATED_UPDATE_USER);
    }


    @Test
    @Transactional
    public void getAllFlowConfigsByCreateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createTime equals to DEFAULT_CREATE_TIME
        defaultFlowConfigShouldBeFound("createTime.equals=" + DEFAULT_CREATE_TIME);

        // Get all the flowConfigList where createTime equals to UPDATED_CREATE_TIME
        defaultFlowConfigShouldNotBeFound("createTime.equals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createTime not equals to DEFAULT_CREATE_TIME
        defaultFlowConfigShouldNotBeFound("createTime.notEquals=" + DEFAULT_CREATE_TIME);

        // Get all the flowConfigList where createTime not equals to UPDATED_CREATE_TIME
        defaultFlowConfigShouldBeFound("createTime.notEquals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createTime in DEFAULT_CREATE_TIME or UPDATED_CREATE_TIME
        defaultFlowConfigShouldBeFound("createTime.in=" + DEFAULT_CREATE_TIME + "," + UPDATED_CREATE_TIME);

        // Get all the flowConfigList where createTime equals to UPDATED_CREATE_TIME
        defaultFlowConfigShouldNotBeFound("createTime.in=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByCreateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where createTime is not null
        defaultFlowConfigShouldBeFound("createTime.specified=true");

        // Get all the flowConfigList where createTime is null
        defaultFlowConfigShouldNotBeFound("createTime.specified=false");
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateTime equals to DEFAULT_UPDATE_TIME
        defaultFlowConfigShouldBeFound("updateTime.equals=" + DEFAULT_UPDATE_TIME);

        // Get all the flowConfigList where updateTime equals to UPDATED_UPDATE_TIME
        defaultFlowConfigShouldNotBeFound("updateTime.equals=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateTime not equals to DEFAULT_UPDATE_TIME
        defaultFlowConfigShouldNotBeFound("updateTime.notEquals=" + DEFAULT_UPDATE_TIME);

        // Get all the flowConfigList where updateTime not equals to UPDATED_UPDATE_TIME
        defaultFlowConfigShouldBeFound("updateTime.notEquals=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateTime in DEFAULT_UPDATE_TIME or UPDATED_UPDATE_TIME
        defaultFlowConfigShouldBeFound("updateTime.in=" + DEFAULT_UPDATE_TIME + "," + UPDATED_UPDATE_TIME);

        // Get all the flowConfigList where updateTime equals to UPDATED_UPDATE_TIME
        defaultFlowConfigShouldNotBeFound("updateTime.in=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByUpdateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        // Get all the flowConfigList where updateTime is not null
        defaultFlowConfigShouldBeFound("updateTime.specified=true");

        // Get all the flowConfigList where updateTime is null
        defaultFlowConfigShouldNotBeFound("updateTime.specified=false");
    }

    @Test
    @Transactional
    public void getAllFlowConfigsByPageSchemaIsEqualToSomething() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);
        PageSchema pageSchema = PageSchemaResourceIT.createEntity(em);
        em.persist(pageSchema);
        em.flush();
        flowConfig.setPageSchema(pageSchema);
        flowConfigRepository.saveAndFlush(flowConfig);
        Long pageSchemaId = pageSchema.getId();

        // Get all the flowConfigList where pageSchema equals to pageSchemaId
        defaultFlowConfigShouldBeFound("pageSchemaId.equals=" + pageSchemaId);

        // Get all the flowConfigList where pageSchema equals to pageSchemaId + 1
        defaultFlowConfigShouldNotBeFound("pageSchemaId.equals=" + (pageSchemaId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultFlowConfigShouldBeFound(String filter) throws Exception {
        restFlowConfigMockMvc.perform(get("/api/flow-configs?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(flowConfig.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].data").value(hasItem(DEFAULT_DATA.toString())))
            .andExpect(jsonPath("$.[*].instanceId").value(hasItem(DEFAULT_INSTANCE_ID)))
            .andExpect(jsonPath("$.[*].createUser").value(hasItem(DEFAULT_CREATE_USER)))
            .andExpect(jsonPath("$.[*].updateUser").value(hasItem(DEFAULT_UPDATE_USER)))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].updateTime").value(hasItem(DEFAULT_UPDATE_TIME.toString())));

        // Check, that the count call also returns 1
        restFlowConfigMockMvc.perform(get("/api/flow-configs/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultFlowConfigShouldNotBeFound(String filter) throws Exception {
        restFlowConfigMockMvc.perform(get("/api/flow-configs?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restFlowConfigMockMvc.perform(get("/api/flow-configs/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingFlowConfig() throws Exception {
        // Get the flowConfig
        restFlowConfigMockMvc.perform(get("/api/flow-configs/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateFlowConfig() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        int databaseSizeBeforeUpdate = flowConfigRepository.findAll().size();

        // Update the flowConfig
        FlowConfig updatedFlowConfig = flowConfigRepository.findById(flowConfig.getId()).get();
        // Disconnect from session so that the updates on updatedFlowConfig are not directly saved in db
        em.detach(updatedFlowConfig);
        updatedFlowConfig
            .name(UPDATED_NAME)
            .data(UPDATED_DATA)
            .instanceId(UPDATED_INSTANCE_ID)
            .createUser(UPDATED_CREATE_USER)
            .updateUser(UPDATED_UPDATE_USER)
            .createTime(UPDATED_CREATE_TIME)
            .updateTime(UPDATED_UPDATE_TIME);
        FlowConfigDTO flowConfigDTO = flowConfigMapper.toDto(updatedFlowConfig);

        restFlowConfigMockMvc.perform(put("/api/flow-configs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(flowConfigDTO)))
            .andExpect(status().isOk());

        // Validate the FlowConfig in the database
        List<FlowConfig> flowConfigList = flowConfigRepository.findAll();
        assertThat(flowConfigList).hasSize(databaseSizeBeforeUpdate);
        FlowConfig testFlowConfig = flowConfigList.get(flowConfigList.size() - 1);
        assertThat(testFlowConfig.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testFlowConfig.getData()).isEqualTo(UPDATED_DATA);
        assertThat(testFlowConfig.getInstanceId()).isEqualTo(UPDATED_INSTANCE_ID);
        assertThat(testFlowConfig.getCreateUser()).isEqualTo(UPDATED_CREATE_USER);
        assertThat(testFlowConfig.getUpdateUser()).isEqualTo(UPDATED_UPDATE_USER);
        assertThat(testFlowConfig.getCreateTime()).isEqualTo(UPDATED_CREATE_TIME);
        assertThat(testFlowConfig.getUpdateTime()).isEqualTo(UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void updateNonExistingFlowConfig() throws Exception {
        int databaseSizeBeforeUpdate = flowConfigRepository.findAll().size();

        // Create the FlowConfig
        FlowConfigDTO flowConfigDTO = flowConfigMapper.toDto(flowConfig);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restFlowConfigMockMvc.perform(put("/api/flow-configs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(flowConfigDTO)))
            .andExpect(status().isBadRequest());

        // Validate the FlowConfig in the database
        List<FlowConfig> flowConfigList = flowConfigRepository.findAll();
        assertThat(flowConfigList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteFlowConfig() throws Exception {
        // Initialize the database
        flowConfigRepository.saveAndFlush(flowConfig);

        int databaseSizeBeforeDelete = flowConfigRepository.findAll().size();

        // Delete the flowConfig
        restFlowConfigMockMvc.perform(delete("/api/flow-configs/{id}", flowConfig.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<FlowConfig> flowConfigList = flowConfigRepository.findAll();
        assertThat(flowConfigList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
